/**
 * [12] 整数转罗马数字
 * # tips: 1 <= num <= 3999 I~IMMMM
 * @format
 * @lc app=leetcode.cn id=12 lang=javascript
 */

// @lc code=start
/**
 * @param {number} num
 * @return {string}
 */
var intToRoman = function (num) {
    const numsTable = { I: 1, IV: 4, V: 5, IX: 9, X: 10, XL: 40, L: 50, XC: 90, C: 100, CD: 400, D: 500, CM: 900, M: 1000 }
    const romans = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
    let [numToRoman, count] = ["", 0]
    for (let char of romans) {
        count = Math.floor(num / numsTable[char])
        num %= numsTable[char]
        while (count > 0) {
            numToRoman += char
            count--
        }
    }
    return numToRoman
}
// debugger
// console.log(intToRoman(1024))
// @lc code=end
